package winOrDie.graphicsInterface;

import java.util.Date;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;



//+:public -:private #:protected $:static F:final
public class Canvas_Test extends Canvas {


	public Canvas_Test(Composite parent, int style) {
		super(parent, SWT.NO_BACKGROUND);// AL poner No_Brackground, la shell no

		paintScenario();
		
		addPaintListener(new PaintListener() {
			//@Override
			public void paintControl(PaintEvent e) {
				Canvas_Test.this.paintControl(e);

			}
		});

		addDisposeListener(new DisposeListener() {
			//@Override
			public void widgetDisposed(DisposeEvent e) {
				Canvas_Test.this.widgetDisposed(e);
			}
		});

		addKeyListener(new KeyListener() {
			Long last_time = 0L;
			Long current_time = 0L;
			Long offset = 400L;
			int keyCode = 0;
			
			@Override
			public void keyReleased(KeyEvent e) {
				// TODO Auto-generated method stub
				System.out.println("Pulsado (1) " + e.character + "->" + e.keyCode + " " + new Date().getTime());
				
			}
			
			@Override
			public void keyPressed(KeyEvent e) {
				current_time = new Date().getTime();
				
				
				
				if (current_time - last_time > offset)
				{
					keyCode = e.keyCode;
					System.out.println("Pulsado " + e.character + "->" + e.keyCode + " " + new Date().getTime());
					last_time = current_time;
				}
					
				
			}
		});
	
	
/*		
		
		
		addKeyListener(new KeyListener() {
			//@Override
			public void keyPressed(KeyEvent e) {
				//System.out.println(e.character);
				
				System.out.println("Pulsado " + e.character + "->" + e.keyCode + " " + new Date().getTime());
				
				
				switch (e.character | e.keyCode) {
				case 'w':
				case 'W':
				case SWT.ARROW_UP:
					//sube
			
	
					break;

				case 's':
				case 'S':
				case SWT.ARROW_DOWN:

					
					break;

				case 'a':
				case 'A':
				case SWT.ARROW_LEFT:

				
					break;

				case 'd':
				case 'D':
				case SWT.ARROW_RIGHT:

					
					break;

				case ' ':

					break;
				}

			}

			//@Override
			public void keyReleased(KeyEvent e) {
				// TODO Auto-generated method stub
				System.out.println("Liberado " + e.character + "->" + e.keyCode + " " + new Date().getTime());
			}
		});*/
	}


	private void paintControl(PaintEvent e) {

	}

	private void widgetDisposed(DisposeEvent e) {

		
	}

	private void paintScenario(){
	
		
	}
	
	public void render() {
		if (!isDisposed()) {
			redraw();
		}
	}

}
